package zheng.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zheng.config.DynamicDataSource;
import zheng.entity.Frend;
import zheng.service.FrendService;

import java.util.List;

/**
 * @author: ztl
 * @date: 2024/02/06 23:06
 * @desc:
 */

@RestController
@RequestMapping("frend")
@Slf4j
public class FrendController {

    @Autowired
    private FrendService frendService;

    @GetMapping(value = "select")
    public List<Frend> select(){
        log.info("select start ...");
        // 读的操作，我们用读库
        DynamicDataSource.name.set("R");
        return frendService.list();
    }


    @GetMapping(value = "insert")
    public void in(){
        log.info("in start ...");
        // 写的操作，我们用写库
        DynamicDataSource.name.set("W");
        Frend frend = new Frend();
        frend.setName("ztl");
        frendService.save(frend);
    }
}
